package com.huika.renrench.control.my.activity;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.volley.Response.Listener;
import com.google.gson.reflect.TypeToken;
import com.huika.renrench.R;
import com.huika.renrench.config.UrlConstants;
import com.huika.renrench.control.common.base.BaseAct;
import com.huika.renrench.http.FormResultRequest;
import com.huika.renrench.http.JSONWrapAjaxParams;
import com.huika.renrench.http.RequestResult;
import com.huika.renrench.support.bean.ReAwardsDetail;
import com.huika.renrench.view.TitleBarHelper;

/**
 * @description：推荐奖励详情
 * @author shicm
 * @date 2015-10-22 上午11:13:20
 */
public class ReAwardsDetailActivity extends BaseAct implements Listener<RequestResult<ReAwardsDetail>>{
	public static final String INP_REAWARDID = "REAWARDID";
    private TextView amountTv,oppositeTv,serialNumTv;
    private TextView orderNoTv,tradeTimeTv,nameTv;
    private TextView phoneTv,proTv;
    private TextView reName;
    private TextView recommended_trade_flag;
    private long reAId = 0;
	private ReAwardsDetail awardsDetail;
	@Override
	public void setRootView() {
		setContentView(R.layout.activity_recommended_awards_detail);
	}
	
	@Override
	protected void initData() {
		reAId = getIntent().getLongExtra(INP_REAWARDID, 0);
		TitleBarHelper barHelper = new TitleBarHelper(this, -1);
		barHelper.setLeftMsg("返回");
		barHelper.setTitleMsg("详情");
		barHelper.setOnLeftClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
				
			}
		});
		super.initData();
	}
	@Override
	protected void initWidget() {
		recommended_trade_flag = (TextView)findViewById(R.id.recommended_trade_flag);
		reName = (TextView) findViewById(R.id.recommended_name_detail);
		amountTv = (TextView)findViewById(R.id.recommended_amount_detail);
		oppositeTv = (TextView)findViewById(R.id.recommended_opposite_info_detail);
		serialNumTv = (TextView)findViewById(R.id.recommended_serial_number_detail);
		orderNoTv = (TextView)findViewById(R.id.recommended_order_no_detail);
		tradeTimeTv = (TextView)findViewById(R.id.recommended_trade_time_detail);
		nameTv = (TextView)findViewById(R.id.inviting_person_tv_name);
		phoneTv = (TextView)findViewById(R.id.inviting_person_tv_phone);
		proTv = (TextView)findViewById(R.id.inviting_person_tv_pro);
		postReAwardData();
		super.initWidget();
	}

	/**
	 * @description：获取推荐奖励详情
	 * @author shicm
	 * @date 2015-10-23 上午9:39:21
	 */
	private void postReAwardData() {
		showLoadingDialog("请稍后...");
		JSONWrapAjaxParams ajaxParams = new JSONWrapAjaxParams();
		ajaxParams.putCommonTypeParam("pid", reAId);
		FormResultRequest<ReAwardsDetail> ReAwardsRequest = new FormResultRequest<ReAwardsDetail>(UrlConstants.MYREWARD_ORDER_DETAIL,
				this, this, new TypeToken<RequestResult<ReAwardsDetail>>() {
				}.getType());	
		ReAwardsRequest.setRequestParams(ajaxParams);
		executeRequest(ReAwardsRequest);
	}

	@Override
	public void onResponse(RequestResult<ReAwardsDetail> arg0) {
		// TODO Auto-generated method stub
		if (arg0.flag == 1) {
			if (arg0 != null && arg0.getRs() != null) {
				awardsDetail = arg0.getRs();
				setData(awardsDetail);
			} else {
			}
		} else {
			showToastMsg(arg0.msg);
		}
		dismissLoadingDialog();
	}

	private void setData(ReAwardsDetail awardsDetail2) {
		recommended_trade_flag.setText(awardsDetail2.getStatus() == 1? "交易成功" : "交易失败");
		reName.setText(awardsDetail2.getDealName());
		amountTv.setText(awardsDetail2.getIsAddOrCut() == 1 ? "+" + awardsDetail2.getAmount() : "-" + awardsDetail2.getAmount());
		oppositeTv.setText(awardsDetail2.getFromInfo());
		serialNumTv.setText("--");
		orderNoTv.setText(awardsDetail2.getOrderNo());
		tradeTimeTv.setText(awardsDetail2.getCreateDt());
		nameTv.setText(awardsDetail2.getRealName());
		phoneTv.setText(awardsDetail2.getPhone());
		proTv.setText(awardsDetail2.getpName());
	}

}
